using System;
using System.Data;
using MySql.Data.MySqlClient;

namespace hemsidan.DataAccess
{
	/// <summary>
	/// Summary description for DBMySQL.
	/// </summary>
	public class DBMySQL : DB
	{
		private MySqlConnection myConn;
		public DBMySQL()
		{
			myConn = new MySqlConnection(Helpers.Settings.ConnStr);
		}

		public override DataSet ExecuteDataSet(string sql)
		{
            try
            {
                MySqlDataAdapter da = new MySqlDataAdapter(sql, myConn);
                myConn.Open();
                DataSet ds = new DataSet();
                da.Fill(ds);
                myConn.Close();

                return ds;
            }
            catch (Exception err)
            {
                System.Web.Mail.SmtpMail.Send("SwiftSite@ohlsons.se", "jan@ohlsons.se", "Felmeddelande", err.Message + "<br>" + err.StackTrace);
            }
            finally
            {
                if (myConn.State == ConnectionState.Open)
                    myConn.Close();
            }
            return null;
		}

		public override void ExecuteNonQuery(string sql)
		{
            try
            {
                MySqlCommand cmd = new MySqlCommand(sql, myConn);
                myConn.Open();
                cmd.ExecuteNonQuery();
                myConn.Close();
            }
            catch (Exception err)
            {
                //Logging
            }
            finally
            {
                if (myConn.State == ConnectionState.Open)
                    myConn.Close();
            }

		}
	}
}
